﻿using Pangeo.Admin.Models.FineReportDb.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace Pangeo.Admin.Services.FineReportDb
{
    public class _FrDbContext : DbContext
    {
        private readonly string _connectionString;

        public _FrDbContext(DbContextOptions<_FrDbContext> options, IConfiguration configuration) : base(options)
        {
            // 从配置中读取连接字符串
            _connectionString = configuration.GetConnectionString("FineReportDb");
        }

        public DbSet<HrmWorkTime> HrmWorkTime { get; set; } // DbSet，用于访问HrmWorkTime表

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // 如果没有在构造函数中提供选项，则使用连接字符串
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(_connectionString);
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<HrmWorkTime>()
                .HasKey(h => new { h.EmpNo, h.ShiftDate }); // 设置复合主键
        }
    }
}
